package com.my12306.train.controller;

import com.my12306.common.model.vo.PageVo;
import com.my12306.common.util.PageUtils;
import com.my12306.common.util.response.ResponseData;
import com.my12306.train.model.entity.DecreaseEntity;
import com.my12306.train.model.vo.DecreaseVO;
import com.my12306.train.service.DecreaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 递远递减率信息
 *
 * @author ËÕÄÁÏ¦
 */
@RestController
@RequestMapping("/decr")
public class DecreaseController {
    @Autowired
    private DecreaseService decreaseService;


    /**
     * 列表
     */
    @PostMapping("/lst")
    public ResponseData list(@RequestBody PageVo pageVo) {
        PageUtils page = decreaseService.queryTicketDecreaseByPage(pageVo);
        return ResponseData.ok().put("page", page);
    }
    /**
     * 信息
     */
    @GetMapping("/inf/{id}")
    public ResponseData info(@PathVariable("id") Long id) {
        DecreaseVO decrease = decreaseService.queryTicketDecreaseById(id);

        return ResponseData.ok().put("decrease", decrease);
    }
    /**
     * 保存
     */
    @RequestMapping("/sv")
    public ResponseData save( @RequestBody DecreaseEntity decrease) {
        System.out.println(decrease);
      return   decreaseService.saveTicketDecrease(decrease);
    }

    /**
     * 修改
     */
    @RequestMapping("/up")
    public ResponseData update(@RequestBody DecreaseEntity decrease) {
        decreaseService.updateTicketDecreaseById(decrease);
        return ResponseData.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/del")
    public ResponseData delete(@RequestBody List<Long> ids) {
        decreaseService.removeTicketDecreaseByIds(ids);
        return ResponseData.ok();
    }

    @GetMapping("/ps.html")
    public ResponseData params(){
      return   decreaseService.queryTicketDecreaseParams();
    }

}
